<?php


         //$str = "Coś tam coś tam sa sdfasfs fsdafa fsadf sd  SA";
           
         
         function CutString($str)
         {
           $str = trim($str);
           $cut = array(" sp ", " sp.", " spółka ", "s.a.");
           $cut2 = array(" sc", "sa");
           foreach ($cut as $c)
           {
            $pos = stripos($str, $c);
            if ($pos)
               $str = substr($str, 0, $pos);
           }
           foreach ($cut2 as $c)
           {
             $pos = strripos($str, $c);
             if ($pos + 2 == strlen($str))
                $str = substr($str, 0, $pos);
           }
           
           return trim($str);
           
         }        
         
        
        require ('classes/DBManager.php');
        
        $str = CutString($_GET['name']);
        $words = explode(" ",$str);
        $query = "SELECT COUNT(*) as count FROM bazkl_clients WHERE upper(name) LIKE upper('%".implode("%') OR upper(name) LIKE upper('%",$words)."%')";
        //$query = "SELECT COUNT(*) as count FROM bazkl_clients WHERE upper(name) LIKE upper('%".$_GET['name']."%')";
        $result = DBManager::getArrayData($query);
        echo mysql_error();
        $data = $result[0];
        echo $data['count'];
?>
